package br.com.ledger.containers;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

import javax.swing.JScrollPane;
import javax.swing.JTextPane;

public class PainelInicial extends JScrollPane implements Runnable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JTextPane content;
	
	public PainelInicial () {
		content = new JTextPane();
		content.setEditable(false);
		content.setContentType("text/html");
		
		setViewportView(content);
		setFocusable(false);
		setBorder(null);
	}


	@Override
	public void run() {
		try {
			File f = new File(getClass().getResource("/docs/init.html").toURI().getPath());
			
			String page = "";
			BufferedReader br = new BufferedReader(new FileReader(f));
			
			String line;
			
			while ((line = br.readLine()) != null)
				page += (line);
			
			content.setContentType("text/html");
			
			String nome = Main.Ledger.getUsuario().getNome();
			String tipo = (Main.Ledger.getUsuario().getTipo_usuario() == 2) ? "Aluno(a)" : "Professor(a)";
			
			String partes[] = page.split("\\$");
			content.setText(partes[0] + tipo + " " + nome + partes[1]);
			
			br.close();
			
			revalidate();
			getParent().validate();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
